package com.cn.项目.飞机预约管理系统.chat;

import javax.swing.*;
import java.awt.*;

public class Mypanel2 extends JPanel {
    //北区域：可根据size的值，创建多个标签和文本框
    protected int size;
    protected JLabel labels[];
    protected JTextField fields[];
    //确定按钮，由派生子类根据具体要求实现
    protected JButton doTask1;
    protected JLabel promptLabel;
    //中区域 ：文本区
    protected JTextArea jTextArea;
    //南区域 ：有派生子类根据具体要求放置不同的图形组件
    JPanel  southPanel;

    public Mypanel2(int mySize){
        setLayout(new BorderLayout());
        //北区域
        size = mySize;
        labels = new JLabel[size];
        fields = new JTextField[size];
        for (int count = 0;count<labels.length;count++){
            labels[count] = new JLabel("标签"+count,SwingConstants.RIGHT);
        }
        for (int count = 0;count<fields.length;count++){
            fields[count] = new JTextField(12);
        }
        JPanel innerPanelCenter = new JPanel();
        for (int count= 0;count<size;count++){
            JPanel innerPanel = new JPanel();
            innerPanel.add(labels[count]);
            innerPanel.add(fields[count]);
            innerPanelCenter.add(innerPanel);
        }
        doTask1 = new JButton("确定");
        innerPanelCenter.add(doTask1);
        promptLabel = new JLabel("设置提示!");
        promptLabel.setForeground(Color.red);
        promptLabel.setBorder(BorderFactory.createTitledBorder("提示"));
        JPanel northPanel = new JPanel(new BorderLayout());
        northPanel.add(innerPanelCenter,BorderLayout.CENTER);
        northPanel.add(promptLabel,BorderLayout.SOUTH);
        add(northPanel,BorderLayout.NORTH);

        //中区域
        jTextArea = new JTextArea();
        //自动换行
        jTextArea.setLineWrap(true);
        //字边界换行
        jTextArea.setWrapStyleWord(true);
        jTextArea.setFont(new Font("幼圆",Font.PLAIN ,16 ));
        add(new JScrollPane(jTextArea),BorderLayout.CENTER);
        //南区域
        //调用本类方法初始化南边图形界面组件
        southPanel = this.setSouthPanel();
        add(this.setSouthPanel(),BorderLayout.SOUTH);


    }

    //
    protected JPanel setSouthPanel(){
        JPanel panelSouth = new JPanel();
        panelSouth.add(new JLabel("子类中需要写南边的图形组件，以满足不同要求！"));
        return panelSouth;
    }

    //
    public static void main(String[] args) {
        JFrame app = new JFrame("通用界面--->父类myPanel2");
        Mypanel2 p = new Mypanel2(1);
        p.labels[0].setText("姓名");
        app.getContentPane().add(p,BorderLayout.CENTER);
        app.setSize(400,300 );
        app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        app.setVisible(true);
    }



}
